package initialize

import (
	"fmt"
	"ginWork/global"
	"ginWork/types"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var err error

func InitMySQL() {
	dsn := "root:123456@tcp(127.0.0.1:3306)/week?charset=utf8mb4&parseTime=True&loc=Local"

	global.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})

	if err != nil {

		fmt.Println("mysql链接失败")
		panic(err)
		return
	}

	fmt.Println("mysql链接成功")

	global.Db.AutoMigrate(types.Goods{})
}
